<?php

namespace App\Admin\Controllers;

use App\Models\Client;
use App\Models\CrmConfig;
use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Request;

class checkRepeatController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '查重';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Client());

        $curl = explode("?",Request::getRequestUri());
        if(isset($curl[1]) && strstr($curl[1],'mobile')){

        }else{
            $grid->model()->where('id','<','1');
        }
        $grid->column('name','客户姓名');
        $grid->column('mobile','手机号码');
        $grid->column('status','客户类型')->using(CrmConfig::getKeyValue('client_status'));
        $grid->column('employee_id','所属销售员')->display(function ($model){
            return User::myTitle($model);
        });

        $grid->disableColumnSelector();
        $grid->disableRowSelector();
        $grid->disablePerPageSelector();
        $grid->disableExport();
        $grid->disableActions();


        $grid->filter(function (Grid\Filter $filter){
            $filter->disableIdFilter();
            $filter->equal('mobile','手机号码');
            $filter->expand();

        });
        $grid->column('true_client','模块')->display(function ($model){
            if($model == 1){
                return '客户';
            }
            return '线索';
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ExampleModel::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ExampleModel);

        $form->display('id', __('ID'));
        $form->display('created_at', __('Created At'));
        $form->display('updated_at', __('Updated At'));

        return $form;
    }
}
